package Demo7;

import java.util.Scanner;

public class Main {
    public static void nixu(int[] array,int left ,int right){
        int[] tmp = new int[right - left + 1];
        for (int i = 0; i < right-left+1 ; i++) {
            tmp[i] = array[right - i];
        }

        for (int i = 0; i < right - left + 1; i++) {
            array[left + i] = tmp[i];
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();   //正整数个数

        int M = sc.nextInt();   //操作次数
        int[] array = new int[N+M+10];


        for (int i = 0; i < N; i++) {
            array[i] = sc.nextInt();
        }

        while (M != 0){
            int x = sc.nextInt(); //操作种类

            //第一种
            if (x == 1){
                int L1 = sc.nextInt();
                int[] arr = new int[L1];
                for (int i = 0; i < L1; i++) {
                    arr[i] = sc.nextInt();
                }
                int L2 = sc.nextInt();
                int[] ret = new int[L2];
                for (int i = 0; i < L2; i++) {
                    ret[i] = sc.nextInt();
                }

                //查找arr有没有在array里面
                int flag = 0;
                for (int i = 0; i < N; i++) {
                    int a = 0;
                    int tmp = 0; //记录位置
                    if (array[i] == arr[0]){
                        tmp = i;
                        for (int j = 0; j < arr.length; j++) {
                            if (array[i+j]!=arr[j]){
                                flag = 0;       //不符合
                                break;
                            }else {
                                flag = 1;   //存在
                            }
                        }
                    }
                    //判断是否替换
                    if (flag == 1){
                        int len = N;
                        int[] tmp2 = new int[len - tmp - L1 + 1];
                        //放到另一个数组
                        for (int j = 0; j < tmp2.length - 1; j++) {
                            tmp2[j] = array[tmp + L1 + j];
                        }
                        //替换上去
                        for (int j = 0; j < L2; j++) {
                            array[tmp+j] = ret[j];
                        }
                        //从替换完之后的位置开始插入
                        for (int j = 0; j < tmp2.length - 1; j++) {
                            array[tmp + L2 + j] = tmp2[j];
                        }
                        N = N -(L1 - L2);
                        break;
                    }

                }
            }
            //第二种
            if (x == 2){
                int len = array.length;
                for (int i = 0; i < len - 1 ; i++) {
                    if ((array[i] + array[i+1]) % 2 == 0){
                        int sum = array[i]+array[i+1];
                        //插入
                        for (int j = len - 1; j > i; j--) {
                            array[j] = array[j-1];
                        }
                        array[i+1] = sum/2;
                        N++;
                        i++;
                    }
                }
                System.out.println();
            }
            //第三种
            if (x == 3){
                int left = sc.nextInt();
                int right = sc.nextInt();
                nixu(array,left - 1,right - 1);
            }
            M--;
        }
        for (int i = 0; i < N - 4; i++) {
            System.out.print(array[i]);
            if (i != N-5){
                System.out.print(" ");
            }
        }
    }
}
